package string;

import com.sun.org.apache.xml.internal.utils.XMLStringFactory;

import javax.lang.model.element.NestingKind;

public class StringDemo {
    public static void main(String[] args) {
        String s1 = "123abc";//创建字符串第一次使用会缓存在常量池中
        String s2 = "123abc";//重用s1对象
        String s3 = "123abc";//复用
        System.out.println(s1 == s2);//true
        System.out.println(s2 == s3);//true
        String s4 = new String("123abc");//创建了一个新的对象，不推荐这种方式
        System.out.println(s1 == s4);//false
        s1 = s1 + "!";
        System.out.println(s1 == s2);
        String s = "123";
        String s5 = s + "abc";
        System.out.println(s5 == s2);
        String s6 = "123" + "abc";
        System.out.println(s6 == s2);


        String s7 = "123abc";
        String s8 = new String("123abc");
        System.out.println(s7.equals(s8));
        System.out.println(s7==s8);
    }
}
